import { BaseWindow } from "../../../component/window/BaseWindow";
import { ILayer } from "../../../mvc/interfaces/ILayer";
import { PageTool } from "../../../common/global/PageTool";
import { Language } from "../../../../extend/language/Language";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ImagesConst } from "../../resource/ImagesConst";
import { TreasureBoxItemRenderer } from "./TreasureBoxItemRenderer";
import { ScrollPolicy } from "../../../../flashx/textLayout/container/ScrollPolicy";
import { PageSelecter } from "../common/pageSelect/PageSelecter";
import { GlobalSkin } from "../../../component/skin/GlobalSkin";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { SOpenTreasureBoxReturn } from "../../../../Message/Public/SOpenTreasureBoxReturn";
import { ItemData } from "../../resource/info/ItemData";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class TreasureBoxItemWindow
    
    export  class TreasureBoxItemWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this._pageTool = new PageTool([], 10);
            setSize(276, 260);
            titleHeight = 30;
            title = Language.getString(27692);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            super.createDisposedChildrenImpl();
            this._bg = ObjCreate.createBg(18, 43, 240, 205, this);
            addChildAt(this._bg, 0);
            this._useTips = ObjCreate.createGTextField("", 18, 50, 240, 20, this, GlobalStyle.getTextFormatCenter(GlobalStyle.textFormat6));
            this._line1 = ObjCreate.createBg(28, 80, 220, 2, this, ImagesConst.SplitLine);
            this._line2 = ObjCreate.createBg(28, 200, 220, 2, this, ImagesConst.SplitLine);
            if (this._tileList == null) 
            {
                this._tileList = ObjCreate.createTileList(25, 88, 220, 100, this);
                this._tileList.setStyle("cellRenderer", TreasureBoxItemRenderer);
                this._tileList.columnWidth = 44;
                this._tileList.rowHeight = 44;
                this._tileList.scrollPolicy = ScrollPolicy.OFF;
            }
            if (this._pagebar == null) 
            {
                this._pagebar = new PageSelecter();
                this._pagebar.mode = PageSelecter.CompleteMode;
                this._pagebar.move(80, 175);
                this._pagebar.maxPage = 2;
                this._pagebar.currentPage = 1;
                this._pagebar.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            }
            addChild(this._pagebar);
            this._btn = ObjCreate.createGButton(Language.getString(27975), 100, 210, 76, 28, this, GlobalSkin.ButtonSpecial);
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            return;
        }

        protected /* override */ disposeImpl(arg1: Boolean=true): void
        {
            super.disposeImpl(arg1);
            this._bg.dispose();
            this._useTips.dispose();
            this._line1.dispose();
            this._line2.dispose();
            this._btn.removeEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._btn.dispose();
            return;
        }

        /* internal  */onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageTool.getByPageNo(this._pagebar.currentPage);
            this._tileList.dataProvider = new DataProvider(loc1);
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        public updateItems(arg1: SOpenTreasureBoxReturn, arg2: int=0): void
        {
            var loc1=null;
            var loc2=null;
            var loc6=null;
            var loc8=undefined;
            var loc9=null;
            var loc3="";
            var loc4="";
            if (arg2 != 0) 
            {
                loc1 = new ItemData(arg2);
                loc3 = loc1.name;
                if (loc2 = new ItemData(loc1.effectEx)) 
                {
                    loc4 = loc2.name;
                }
            }
            if (loc3 != "") 
            {
                this._useTips.htmlText = Language.getString(30326) + loc3 + "*" + arg1.amount + " " + loc4 + "*" + arg1.amount;
            }
            else 
            {
                this._useTips.htmlText = Language.getStringByParam(30325, arg1.amount, arg1.amount);
            }
            var loc5=[];
            var loc7=arg1.itemAmount;
            var loc10=0;
            var loc11=loc7;
            for (loc8 in loc11) 
            {
                (loc6 = new ItemData(loc8)).itemAmount = loc7[loc8];
                loc5.push(loc6);
            }
            this._pageTool.array = loc5;
            this._pagebar.currentPage = 1;
            this._pagebar.maxPage = Math.ceil(loc5.length / 10);
            loc9 = this._pageTool.getByPageNo(1);
            this._tileList.dataProvider = new DataProvider(loc9);
            return;
        }

        /* internal */ /* var */_useTips: GTextFiled;

        /* internal */ /* var */_pagebar: PageSelecter;

        /* internal */ /* var */_pageTool: PageTool;

        /* internal */ /* var */_tileList: GTileList;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_line1: ScaleBitmap;

        /* internal */ /* var */_line2: ScaleBitmap;

        /* internal */ /* var */_btn: GButton;
    }
